package com.dmap.community.controller.app;

import com.dmap.base.vo.BaseVo;
import com.dmap.community.constant.Constant;
import com.dmap.community.controller.app.param.ReplyCommentPraiseParam;
import com.dmap.community.controller.app.param.ReplyPraiseParam;
import com.dmap.community.service.community.PraiseService;
import com.dmap.community.vo.NormalResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * \* User: silent
 * \* Date: 14/11/17 Time: 17:56
 * \* Description:
 * \
 */
@Api(value = "社区主题点赞/社区评论点赞", description = "App/社区主题点赞/社区评论点赞")
@RestController
@RequestMapping(value = "/api/dmap-community-server/v1/community/praise")
public class PraiseController {
    @Resource
    private PraiseService praiseService;

    @ResponseBody
    @ApiOperation(value = "点赞社区主题评论(一级回复点赞)", notes = "点赞社区主题评论(一级回复点赞)")
    @RequestMapping(value = "reply/insert", method = RequestMethod.POST)
    public BaseVo insertReplyPraise(@RequestBody ReplyPraiseParam param) {
        BaseVo result = new BaseVo();
        if (param.getReplyId() == 0 || param.getUserId() == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = praiseService.insertReplyPraise(param.getReplyId(), param.getUserId());
        if (success == 0) {
            result.setCode(Constant.RESPONSE_INSERT_ERROR);
            result.setMsg(Constant.RESPONSE_INSERT_ERROR_MSG);
        }
        return result;
    }


    @ResponseBody
    @ApiOperation(value = "点赞社区主题评论回复(二级回复点赞)", notes = "点赞社区主题评论回复(二级回复点赞)")
    @RequestMapping(value = "reply/comment/insert", method = RequestMethod.POST)
    public BaseVo insertReplyCommentPraise(@RequestBody ReplyCommentPraiseParam param) {
        BaseVo result = new BaseVo();
        if (param.getCommentId() == 0 || param.getUserId() == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = praiseService.insertReplyCommentPraise(param.getCommentId(), param.getUserId());
        if (success == 0) {
            result.setCode(Constant.RESPONSE_INSERT_ERROR);
            result.setMsg(Constant.RESPONSE_INSERT_ERROR_MSG);
        }
        return result;
    }


    @ResponseBody
    @ApiOperation(value = "取消点赞社区主题评论(一级回复取消点赞)", notes = "取消点赞社区主题评论(一级回复取消点赞)")
    @RequestMapping(value = "reply/delete/{replyId}/{userId}", method = RequestMethod.DELETE)
    public BaseVo deleteReplyPraise(@PathVariable(value = "replyId") long replyId,@PathVariable(value = "userId") long userId) {
        BaseVo result = new BaseVo();
        if (replyId == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = praiseService.deleteReplyPraise(replyId,userId);
        if (success == 0) {
            result.setCode(Constant.RESPONSE_DELETE_ERROR);
            result.setMsg(Constant.RESPONSE_DELETE_ERROR_MSG);
        }
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "取消点赞社区主题评论回复(二级回复取消点赞)", notes = "取消点赞社区主题评论回复(二级回复取消点赞)")
    @RequestMapping(value = "reply/comment/delete/{commentId}/{userId}", method = RequestMethod.DELETE)
    public BaseVo deleteReplyCommentPraise(@PathVariable(value = "commentId") long commentId,@PathVariable(value = "userId") long userId) {
        BaseVo result = new BaseVo();
        if (commentId == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = praiseService.deleteReplyCommentPraise(commentId,userId);
        if (success == 0) {
            result.setCode(Constant.RESPONSE_DELETE_ERROR);
            result.setMsg(Constant.RESPONSE_DELETE_ERROR_MSG);
        }
        return result;
    }
}
